package com.rndemo;

import android.util.Log;
import android.widget.Toast;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.views.scroll.ReactScrollView;

/**
 * ReactNative调用Android原生方法
 * https://blog.csdn.net/u014131921/article/details/54668595
 * Created by tiangui on 2018/4/9.
 */
public class MyRN extends ReactContextBaseJavaModule {

    private static final String TAG = "ReactNative-MyRN";

    public static int sFlag = 0;

    public MyRN(ReactApplicationContext reactContext) {
        super(reactContext);
    }

    // ReactContextBaseJavaModule要求派生类实现getName方法。
    // 这个函数返回一个字符串，用于在JavaScript端标记这个原生模块。
    @Override
    public String getName() {
        return "MyRN";
    }

    // 要导出一个方法给JavaScript使用，Java方法需要使用注解@ReactMethod
    @ReactMethod
    public void toastPackageName() {
        Log.d(TAG, "toastPackageName()");
        String name = getReactApplicationContext().getPackageName();
        toastString(name);
    }

    @ReactMethod
    public void toastString(String str) {
        Log.d(TAG, "toastString()");
        Toast.makeText(getReactApplicationContext(), str, Toast.LENGTH_LONG).show();
    }

    @ReactMethod
    public void setFlag(int num) {
        Log.d(TAG, "setFlag(): " + num);
        sFlag = num;
    }

    /**
     * 启动云帆短视频的Activity
     */
    @ReactMethod
    public void startShortVideo() {
        //getReactApplicationContext().startActivity(new Intent(getReactApplicationContext(), com.yfcloud.shortvideo.activity.MainActivity.class));
    }

}
